<template>
  <div>
    <el-tabs v-model="activeName" type="card" class="demo-tabs" @tab-click="handleClick">
      <el-tab-pane label="待审核" name="待审核">
        <el-form :model="ToBeReviewed" inline>
          <el-form-item label="仓库：">
            <el-select v-model="ToBeReviewed.warehouseId" clearable>
              <el-option :label="item.name" :value="item.id" v-for="item in store.NewHouseList" :key="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="订单号：">
            <el-input v-model="ToBeReviewed.tid" clearable />
          </el-form-item>
          <el-form-item label="订单来源平台：">
            <el-select v-model="ToBeReviewed.region">
              <el-option :label="item.name" :value="item.id" v-for="item in store.getOrderPlatformListArr"
                :key="item.id" clearable />
            </el-select>
          </el-form-item>
          <el-form-item label="货主：">
            <el-select v-model="ToBeReviewed.company" clearable>
              <el-option :label="item" :value="item" v-for="item in store.getCompanyListBtnArr" :key="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="订单类型：">
            <el-select v-model="ToBeReviewed.typeId" clearable>
              <el-option :label="item.name" :value="item.id" v-for="item in store.preSaleOrdergetOrderTypeListArr"
                :key="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="ToBeReviewedOnSubmit">搜索</el-button>
            <el-button type="primary" @click="everyToBeReviewedOnSubmit(1)">批量审核</el-button>
          </el-form-item>
        </el-form>
        <div class="table">
          <el-table :data="tableData" style="width: 100%" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" />
            <el-table-column label="订单来源平台" width="120">
              <template #default="scope">{{ scope.row.orderPlatformName }}</template>
            </el-table-column>
            <el-table-column label="订单类型" width="120">
              <template #default="scope">{{ scope.row.orderTypeName }}</template>
            </el-table-column>
            <el-table-column label="订单号" width="220">
              <template #default="scope">{{ scope.row.tid }}</template>
            </el-table-column>
            <el-table-column label="子订单号" width="220">
              <template #default="scope">{{ scope.row.orderOid }}</template>
            </el-table-column>
            <el-table-column label="成交时间" width="180">
              <template #default="scope">{{ scope.row.payTime }}</template>
            </el-table-column>
            <el-table-column label="卖家备注" width="220">
              <template #default="scope">{{ scope.row.sellerFlagName + scope.row.sellerMemo }}</template>
            </el-table-column>
            <el-table-column label="订单状态" width="150">
              <template #default="scope">{{ scope.row.orderStatusName }}</template>
            </el-table-column>
            <el-table-column label="操作">
              <template #default="scope">
                <el-button link type="primary" size="small" @click.prevent="everyToBeReviewedOnSubmit(2, scope.row)">
                  审核通过
                </el-button>
                <el-button link type="primary" size="small" @click.prevent="openStallDiaog(scope.row)">
                  档口拿货
                </el-button>
                <el-button link type="primary" size="small" @click.prevent="returnXs(scope.row)" v-if="loading">
                  返回线上采购
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 档口拿货 -->
        <div>
          <el-dialog v-model="stallDialogVisible" width="700">
            <span>
              <div style="display: flex;align-items: center;">
                <span>需拿货总数量：</span><el-input style="width: 200px;" v-model="purchaseNum" clearable />
                <span>选择档口：</span>
                <el-select v-model="productGearId" clearable>
                  <el-option :label="item.value" :value="item.key" v-for="item in store.productGearListTable"
                    :key="item.key" />
                </el-select>
                <el-button type="primary" @click="productGearPurchaseCreateSubmit">
                  确定
                </el-button>
              </div>
            </span>
          </el-dialog>
        </div>
      </el-tab-pane>
      <!-- <el-tab-pane label="拣货单列表" name="拣货单列表">
        <el-form :model="pickingListForm" inline>
          <el-form-item label="仓库：">
            <el-select v-model="pickingListForm.warehouseId">
              <el-option :label="item.name" :value="item.id" v-for="item in store.houseList" :key="item.id"
                @click="pickingListFormOnSubmit" clearable />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="pickingListFormOnSubmitSet">选中的加入拣货单</el-button>
          </el-form-item>
        </el-form>
        <div class="table">
          <el-table :data="pickingListTableData" style="width: 100%" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" />
            <el-table-column label="库位" width="120">
              <template #default="scope">{{ scope.row.warehouseLocationName }}</template>
            </el-table-column>
            <el-table-column label="SKU信息" width="120">
              <template #default="scope">{{ scope.row.orderSkuPropertiesName }}</template>
            </el-table-column>
            <el-table-column label="需拣数量" width="220">
              <template #default="scope">{{ scope.row.orderNum }}</template>
            </el-table-column>
            <el-table-column label="操作">
              <template #default="scope">
                <el-button link type="primary" size="small" @click.prevent="deleteRowPicking(scope.row)" v-if="loading">
                  取消并返回线上采购
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-tab-pane> -->
      <el-tab-pane label="待拣货" name="待拣货">
        <el-tabs v-model="activeNameSon" class="demo-tabs" @tab-click="pickingListFormOnSubmit">
          <el-tab-pane label="未虚拟发货" name="未虚拟发货">
            <el-form :model="pickingListForm" inline>
              <el-form-item label="仓库：">
                <el-select v-model="pickingListForm.warehouseId" clearable>
                  <el-option :label="item.name" :value="item.id" v-for="item in store.NewHouseList" :key="item.id" />
                </el-select>
              </el-form-item>
              <el-form-item label="订单状态：">
                <el-select v-model="pickingListForm.orderStatus" clearable>
                  <el-option :label="item.name" :value="item.code" v-for="item in pickSaleOrdergetOrderStatusListArr"
                    :key="item.code" />
                </el-select>
              </el-form-item>
              <el-form-item label="库位：">
                <el-select v-model="pickingListForm.warehouseLocationId" clearable>
                  <el-option :label="item.name" :value="item.id" v-for="item in WarehouseLocationIdList"
                    :key="item.id" />
                </el-select>
              </el-form-item>
              <el-form-item label="订单号：">
                <el-input v-model="pickingListForm.tid" clearable />
              </el-form-item>
              <el-form-item label="所属店铺">
                <el-select v-model="pickingListForm.shopName">
                  <el-option :label="item" :value="item" v-for="(item, index) in getShopnameArr" :key="index"
                    clearable />
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="pickingListFormOnSubmit">搜索</el-button>
              </el-form-item>
            </el-form>
            <div>
              <el-button type="primary" @click="printMyTag(multipleSelection)">批量打印标签</el-button>
              <el-button type="primary" @click="TagVirtualDelivery(multipleSelection)">批量虚拟发货</el-button>
            </div>
            <div class="table">
              <el-table :data="pickingListTableData" style="max-width: 1640px" @selection-change="handleSelectionChange"
                max-height="650">
                <el-table-column type="selection" width="55" />

                <el-table-column label="订单号" width="220">
                  <template #default="scope">{{ scope.row.tid }}</template>
                </el-table-column>
                <el-table-column label="子订单号" width="220">
                  <template #default="scope">{{ scope.row.orderOid }}</template>
                </el-table-column>
                <el-table-column label="SKU图片" width="220">
                  <template #default="scope"><el-image style="width: 40px; height: 40px"
                      :src="scope.row.orderPicPath" /></template>
                </el-table-column>
                <el-table-column label="SKU信息" width="220">
                  <template #default="scope">{{ scope.row.orderSkuPropertiesName }}</template>
                </el-table-column>
                <el-table-column label="所属店铺" width="220">
                  <template #default="scope">{{ scope.row.title }}</template>
                </el-table-column>
                <el-table-column label="成交时间" width="180">
                  <template #default="scope">{{ scope.row.payTime }}</template>
                </el-table-column>
                <el-table-column label="卖家备注" width="220">
                  <template #default="scope">{{ scope.row.sellerMemo }}</template>
                </el-table-column>
                <el-table-column label="订单状态" width="150">
                  <template #default="scope">{{ scope.row.orderStatusName }}</template>
                </el-table-column>
                <el-table-column label="库位" width="150">
                  <template #default="scope">{{ scope.row.warehouseLocationName }}</template>
                </el-table-column>
                <el-table-column label="操作" width="280">
                  <template #default="scope">
                    <el-button link type="primary" size="small" @click.prevent="TagVirtualDelivery(scope.row)">
                      虚拟发货
                    </el-button>
                    <el-button link type="primary" size="small" @click.prevent="printMyTag(scope.row)">
                      打印标签
                    </el-button>
                    <el-button link type="primary" size="small" @click.prevent="deleteRowPicking(scope.row)">
                      返回线上采购
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
          <el-tab-pane label="已虚拟发货" name="已虚拟发货">
            <el-form :model="pickingListForm" inline>
              <el-form-item label="仓库：">
                <el-select v-model="pickingListForm.warehouseId" clearable>
                  <el-option :label="item.name" :value="item.id" v-for="item in store.NewHouseList" :key="item.id" />
                </el-select>
              </el-form-item>
              <el-form-item label="订单状态：">
                <el-select v-model="pickingListForm.orderStatus" clearable>
                  <el-option :label="item.name" :value="item.code" v-for="item in pickSaleOrdergetOrderStatusListArr"
                    :key="item.code" />
                </el-select>
              </el-form-item>
              <el-form-item label="库位：">
                <el-select v-model="pickingListForm.warehouseLocationId" clearable>
                  <el-option :label="item.name" :value="item.id" v-for="item in WarehouseLocationIdList"
                    :key="item.id" />
                </el-select>
              </el-form-item>
              <el-form-item label="订单号：">
                <el-input v-model="pickingListForm.tid" clearable />
              </el-form-item>
              <el-form-item label="所属店铺">
                <el-select v-model="pickingListForm.shopName">
                  <el-option :label="item" :value="item" v-for="(item, index) in getShopnameArr" :key="index"
                    clearable />
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="pickingListFormOnSubmit">搜索</el-button>
              </el-form-item>
            </el-form>
            <div>
              <el-button type="primary" @click="printMyTag(multipleSelection)">批量打印标签</el-button>
            </div>
            <div class="table">
              <el-table :data="pickingListTableData" style="max-width: 1640px" @selection-change="handleSelectionChange"
                max-height="650">
                <el-table-column type="selection" width="55" />

                <el-table-column label="订单号" width="220">
                  <template #default="scope">{{ scope.row.tid }}</template>
                </el-table-column>
                <el-table-column label="子订单号" width="220">
                  <template #default="scope">{{ scope.row.orderOid }}</template>
                </el-table-column>
                <el-table-column label="SKU图片" width="220">
                  <template #default="scope"><el-image style="width: 40px; height: 40px"
                      :src="scope.row.orderPicPath" /></template>
                </el-table-column>
                <el-table-column label="SKU信息" width="220">
                  <template #default="scope">{{ scope.row.orderSkuPropertiesName }}</template>
                </el-table-column>
                <el-table-column label="所属店铺" width="220">
                  <template #default="scope">{{ scope.row.title }}</template>
                </el-table-column>
                <el-table-column label="成交时间" width="180">
                  <template #default="scope">{{ scope.row.payTime }}</template>
                </el-table-column>
                <el-table-column label="卖家备注" width="220">
                  <template #default="scope">{{ scope.row.sellerMemo }}</template>
                </el-table-column>
                <el-table-column label="订单状态" width="150">
                  <template #default="scope">{{ scope.row.orderStatusName }}</template>
                </el-table-column>
                <el-table-column label="库位" width="150">
                  <template #default="scope">{{ scope.row.warehouseLocationName }}</template>
                </el-table-column>
                <el-table-column label="操作" width="280">
                  <template #default="scope">
                    <el-button link size="small" :disabled="true">
                      已虚拟发货
                    </el-button>
                    <el-button link type="primary" size="small" @click.prevent="printMyTag(scope.row)">
                      打印标签
                    </el-button>
                    <el-button link type="primary" size="small" @click.prevent="deleteRowPicking(scope.row)">
                      返回线上采购
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
        </el-tabs>
        <!--
        <el-form :model="awaitPickForm" inline>
          <el-form-item label="仓库：">
            <el-select v-model="awaitPickForm.warehouseId" clearable>
              <el-option :label="item.name" :value="item.id" v-for="item in store.houseList" :key="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="订单号：">
            <el-input v-model="awaitPickForm.orderNum" clearable />
          </el-form-item>
          <el-form-item label="拣货单状态：">
            <el-select v-model="awaitPickForm.status" clearable>
              <el-option label="全部" :value="-1" />
              <el-option label="未开始" :value="0" />
              <el-option label="拣货中" :value="1" />
              <el-option label="已完成" :value="2" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="awaitPickonSubmit">搜索</el-button>
            <el-button type="primary" @click="batchPrintExpress">选中批量打印拣货单</el-button>
          </el-form-item>
        </el-form>
        <div class="table">
          <el-table :data="awaitPickTableData" style="width: 100%" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" />
            <el-table-column label="拣货单单号" width="120">
              <template #default="scope">{{ scope.row.orderNum }}</template>
            </el-table-column>
            <el-table-column label="拣货单生成时间" width="180">
              <template #default="scope">{{ scope.row.createTime }}</template>
            </el-table-column>
            <el-table-column label="拣货单状态" width="220">
              <template #default="scope">{{
                scope.row.status == 0 ? '未开始' : scope.row.status == 1 ? '拣货中' : scope.row.status == 2 ? '已完成' : ''
              }}</template>
            </el-table-column>
            <el-table-column label="拣货单完成时间" width="220">
              <template #default="scope">{{ scope.row.completeTime }}</template>
            </el-table-column>
            <el-table-column label="操作">
              <template #default="scope">
                <el-button link type="primary" size="small"
                  @click.prevent=" getPrePickOrderDetailPrePickOrderBtn(scope.row.id)">
                  详情
                </el-button>
                <el-button link type="primary" size="small"
                  @click.prevent="prePickOrderBatchPrintExpressOrderBtn(scope.row.id)">
                  打印快递面单
                </el-button>
                <el-button link type="primary" size="small" @click.prevent="getPrePickOrderDetailBtn(scope.row.id)">
                  打印拣货单
                </el-button>
              </template>
            </el-table-column>
          </el-table>

        </div>
      -->
        <el-dialog v-model="TagdialogVisible" width="500">
          <span>
            <el-form :model="Tagform" style="max-width: 500px">
              <el-form-item label="取货人：">
                <el-select v-model="Tagform.getPeopleName" clearable>
                  <el-option :label="item.name" :value="item.name" v-for="item in PickPersonList" :key="item.id" />
                </el-select>
              </el-form-item>
            </el-form>
          </span>
          <template #footer>
            <div class="dialog-footer">
              <el-button @click="TagdialogVisible = false">取消</el-button>
              <el-button type="primary" @click="submitTagPrint(ContentBottom)">
                确定
              </el-button>
            </div>
          </template>
        </el-dialog>
      </el-tab-pane>
      <!-- <el-button link type="primary" size="small" @click.prevent="printProductPurchaseStorageBtn()">
            打印快递面单
          </el-button> -->
      <el-tab-pane label="取号失败列表" name="取号失败列表">
        <el-form :model="failingListForm" inline>
          <el-form-item label="子订单号：">
            <el-input v-model="failingListForm.orderOid" style="width: 130px;" clearable />
          </el-form-item>
          <el-form-item label="拣货单单号：">
            <el-input v-model="failingListForm.prePickOrderNum" clearable />
          </el-form-item>
          <el-form-item label="失败原因：">
            <el-select v-model="failingListForm.failMsg" clearable>
              <el-option :label="item" :value="item" v-for="(item, index) in loser" :key="index" />
            </el-select>
          </el-form-item>
          <el-form-item label="成交时间：">
            <el-date-picker v-model="failingListForm.times" type="datetimerange" start-placeholder="开始时间"
              value-format="x" end-placeholder="结束时间" time-format="A hh:mm:ss" clearable />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="failingListOnSubmit">搜索</el-button>
            <el-button type="primary" @click="failingListOnSubmitONe">选中一键处理</el-button>
          </el-form-item>
        </el-form>
        <div class="table">
          <el-table :data="failingListTable" style="width: 100%" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" />
            <el-table-column label="拣货单单号" width="220">
              <template #default="scope">{{ scope.row.prePickOrderNum }}</template>
            </el-table-column>
            <el-table-column label="订单号" width="220">
              <template #default="scope">{{ scope.row.orderOidStr }}</template>
            </el-table-column>
            <el-table-column label="成交时间" width="220">
              <template #default="scope">{{ scope.row.payTime }}</template>
            </el-table-column>
            <el-table-column label="失败原因" width="400">
              <template #default="scope">{{ scope.row.failMsg }}</template>
            </el-table-column>
            <el-table-column label="操作">
              <template #default="scope">
                <el-button link type="primary" size="small" v-if="scope.row.operationTypeId == 1 && loading"
                  @click.prevent="ignoreOrderBtn(scope.row)">
                  忽略
                </el-button>
                <el-button link type="primary" size="small" v-if="scope.row.operationTypeId == 2"
                  @click.prevent="regainOrder(scope.row)">
                  重新获取订单
                </el-button>
                <el-button link type="primary" size="small" v-if='scope.row.operationTypeId == 3'
                  @click.prevent="ExchangeExpress(scope.row)">
                  换快递
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-dialog v-model="retlowSerDialogVisible" width="500">
            <span>
              选择快递<el-select v-model="expressNow">
                <el-option :label="item.name" :value="item.id" v-for="item in rowNowContent" :key="item.key" />
              </el-select>
            </span>
            <template #footer>
              <div class="dialog-footer">
                <el-button @click="retlowSerDialogVisible = false">取消</el-button>
                <el-button type="primary" @click="submitExpress">
                  确定
                </el-button>
              </div>
            </template>
          </el-dialog>
        </div>
      </el-tab-pane>
      <el-tab-pane label="提前发货" name="提前发货">
        <el-tabs v-model="advance" class="demo-tabs" @tab-click="preDeliveryListSelect">
          <el-tab-pane label="未虚拟发货" name="未虚拟发货">
            <el-form :model="preDeliveryForm" inline>
              <el-form-item label="仓库：">
                <el-select v-model="preDeliveryForm.warehouseId" clearable>
                  <el-option label="全部" value="-1" />
                  <el-option :label="item.name" :value="item.id" v-for="item in store.houseList" :key="item.id" />
                </el-select>
              </el-form-item>
              <el-form-item label="订单号：">
                <el-input v-model="preDeliveryForm.tid" style="width: 130px;" clearable />
              </el-form-item>
              <el-form-item label="订单来源平台：">
                <el-select v-model="preDeliveryForm.platformCode" clearable>
                  <el-option :label="item.name" :value="item.id" v-for="item in store.getOrderPlatformListArr"
                    :key="item.id" clearable />
                </el-select>
              </el-form-item>
              <el-form-item label="旗帜：">
                <el-select v-model="preDeliveryForm.sellerFlag" clearable>
                  <el-option :label="item.name
                    " :value="item.id" v-for="(item, index) in flagArr" :key="index" />
                </el-select>
              </el-form-item>
              <!-- <el-form-item label="订单类型">
            <el-select v-model="preDeliveryForm.failMsg" clearable>
              <el-option :label="item.name" :value="item.id" v-for="item in store.preSaleOrdergetOrderTypeListArr"
                :key="item.id" />
            </el-select>
          </el-form-item> -->
              <el-form-item label="店铺：">
                <el-select v-model="preDeliveryForm.shopName" clearable>
                  <el-option :label="item" :value="item" v-for="(item, index) in ShopNameListArr" :key="index" />
                </el-select>
              </el-form-item>
              <el-form-item label="拿货档口:">
                <el-select v-model="preDeliveryForm.gearOpenId" clearable>
                  <el-option :label="item.name" :value="item.id" v-for="(item, index) in selectArr" :key="index" />
                </el-select>
              </el-form-item>
              <el-form-item label="成交时间：">
                <el-date-picker v-model="preDeliveryFormtimes" type="datetimerange" start-placeholder="开始时间"
                  value-format="x" end-placeholder="结束时间" time-format="A hh:mm:ss" clearable />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="preDeliveryListSelect">搜索</el-button>
              </el-form-item>
            </el-form>
            <div>
              <el-button @click="printOneEvery(multipleSelection)">一键打印标签</el-button>
              <el-button @click="toCheckSheet">生成报货单</el-button>
              <el-button @click="VirtualDelivery(multipleSelection)
                ">一键虚拟发货</el-button>
            </div>
            <div class="table">
              <el-table :data="preDeliveryListTable" max-height="560" style="width: 1600px;"
                @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" />
                <el-table-column label="订单来源平台" width="125">
                  <template #default="scope">{{ scope.row.platform }}</template>
                </el-table-column>
                <!-- <el-table-column label="订单类型" width="125">
              <template #default="scope">{{ scope.row.orderOidStr }}</template>
            </el-table-column> -->
                <el-table-column label="所属店铺" width="225">
                  <template #default="scope">{{ scope.row.title }}</template>
                </el-table-column>
                <el-table-column label="订单号" width="225">
                  <template #default="scope">{{ scope.row.tid }}</template>
                </el-table-column>
                <el-table-column label="子订单号" width="225">
                  <template #default="scope">{{ scope.row.orderOid }}</template>
                </el-table-column>
                <el-table-column label="成交时间" width="225">
                  <template #default="scope">{{ scope.row.payTime }}</template>
                </el-table-column>
                <el-table-column label="商品图片">
                  <template #default="scope">
                    <el-image style="width: 40px; height: 40px" :src="scope.row.orderPicPath" />
                  </template>
                </el-table-column>
                <el-table-column label="商品信息" width="225">
                  <template #default="scope">{{ scope.row.orderSkuPropertiesName }}</template>
                </el-table-column>
                <el-table-column label="档口号" width="125">
                  <template #default="scope">{{ scope.row.gearOpenNum }}</template>
                </el-table-column>
                <el-table-column label="拿货档口" width="125">
                  <template #default="scope">{{ scope.row.gearOpenName }}</template>
                </el-table-column>
                <el-table-column label="拿货数量" width="125">
                  <template #default="scope">{{ scope.row.orderNum }}</template>
                </el-table-column>
                <el-table-column label="拿货价" width="125">
                  <template #default="scope">{{ scope.row.purchasePrice }} <span style="color: skyblue;"
                      class="headclass" @click="openEvery(scope.row)">更多</span>
                  </template>
                </el-table-column>
                <el-table-column label="卖家备注" width="225">
                  <template #default="scope"><img style="width: 20px;height: 20px " :src="'http://yitaoweb.sc.kuaidi600.com/flag_color/op_memo_' +
                    Number(scope.row.sellerFlag) +
                    '.png'
                    " alt="" />{{ scope.row.sellerMemo }}</template>
                </el-table-column>
                <el-table-column label="订单状态" width="125">
                  <template #default="scope">{{ scope.row.orderStatus }}</template>
                </el-table-column>
                <el-table-column label="拿货状态" width="125">
                  <template #default="scope">{{ (scope.row.isGetGood == 1 ? '未拿货' : scope.row.isGetGood == 2 ?
                    '已拿货' : scope.row.isGetGood == 3 ? "缺货" : '') + ',' + (!!scope.row.getGoodDate ?
                      scope.row.getGoodDate.slice(0, 10) +
                      '到货' : '') }}</template>
                </el-table-column>
                <el-table-column label="是否虚拟发货" width="125">
                  <template #default="scope">{{ scope.row.isSend == 1 ? '是' : scope.row.isSend == 0 ? '否' : ''
                    }}</template>
                </el-table-column>
                <el-table-column label="操作" width="300">
                  <template #default="scope">
                    <el-button link type="primary" size="small" @click.prevent="stockoutBtn(scope.row)">
                      缺货
                    </el-button>
                    <el-button link type="primary" size="small" @click.prevent="VirtualDelivery(scope.row)">
                      虚拟发货
                    </el-button>
                    <el-button link type="primary" size="small" @click.prevent="printOneEvery(scope.row)">
                      <span v-if="scope.row.isPrint === 0">打印标签</span> <span v-if="scope.row.isPrint === 1">重新打印</span>
                    </el-button>
                    <el-button link type="primary" size="small" @click.prevent="preDeliveryPurchasing(scope.row)">
                      返回线上采购
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
          <el-tab-pane label="已虚拟发货" name="已虚拟发货">
            <el-form :model="preDeliveryForm" inline>
              <el-form-item label="仓库：">
                <el-select v-model="preDeliveryForm.warehouseId" clearable>
                  <el-option label="全部" value="-1" />
                  <el-option :label="item.name" :value="item.id" v-for="item in store.houseList" :key="item.id" />
                </el-select>
              </el-form-item>
              <el-form-item label="订单号：">
                <el-input v-model="preDeliveryForm.tid" style="width: 130px;" clearable />
              </el-form-item>
              <el-form-item label="订单来源平台：">
                <el-select v-model="preDeliveryForm.platformCode" clearable>
                  <el-option :label="item.name" :value="item.id" v-for="item in store.getOrderPlatformListArr"
                    :key="item.id" clearable />
                </el-select>
              </el-form-item>
              <el-form-item label="旗帜：">
                <el-select v-model="preDeliveryForm.sellerFlag" clearable>
                  <el-option :label="item.name
                    " :value="item.id" v-for="(item, index) in flagArr" :key="index" />
                </el-select>
              </el-form-item>
              <!-- <el-form-item label="订单类型">
            <el-select v-model="preDeliveryForm.failMsg" clearable>
              <el-option :label="item.name" :value="item.id" v-for="item in store.preSaleOrdergetOrderTypeListArr"
                :key="item.id" />
            </el-select>
          </el-form-item> -->
              <el-form-item label="店铺：">
                <el-select v-model="preDeliveryForm.shopName" clearable>
                  <el-option :label="item" :value="item" v-for="(item, index) in ShopNameListArr" :key="index" />
                </el-select>
              </el-form-item>
              <el-form-item label="拿货档口:">
                <el-select v-model="preDeliveryForm.gearOpenId" clearable>
                  <el-option :label="item.name" :value="item.id" v-for="(item, index) in selectArr" :key="index" />
                </el-select>
              </el-form-item>
              <el-form-item label="成交时间：">
                <el-date-picker v-model="preDeliveryFormtimes" type="datetimerange" start-placeholder="开始时间"
                  value-format="x" end-placeholder="结束时间" time-format="A hh:mm:ss" clearable />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="preDeliveryListSelect">搜索</el-button>
              </el-form-item>
            </el-form>
            <div>
              <el-button @click="printOneEvery(multipleSelection)">一键打印标签</el-button>
              <el-button @click="toCheckSheet">生成报货单</el-button>
            </div>
            <div class="table">
              <el-table :data="preDeliveryListTable" max-height="560" style="width: 1600px;"
                @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" />
                <el-table-column label="订单来源平台" width="125">
                  <template #default="scope">{{ scope.row.platform }}</template>
                </el-table-column>
                <!-- <el-table-column label="订单类型" width="125">
              <template #default="scope">{{ scope.row.orderOidStr }}</template>
            </el-table-column> -->
                <el-table-column label="所属店铺" width="225">
                  <template #default="scope">{{ scope.row.title }}</template>
                </el-table-column>
                <el-table-column label="订单号" width="225">
                  <template #default="scope">{{ scope.row.tid }}</template>
                </el-table-column>
                <el-table-column label="子订单号" width="225">
                  <template #default="scope">{{ scope.row.orderOid }}</template>
                </el-table-column>
                <el-table-column label="成交时间" width="225">
                  <template #default="scope">{{ scope.row.payTime }}</template>
                </el-table-column>
                <el-table-column label="商品图片">
                  <template #default="scope">
                    <el-image style="width: 40px; height: 40px" :src="scope.row.orderPicPath" />
                  </template>
                </el-table-column>
                <el-table-column label="商品信息" width="225">
                  <template #default="scope">{{ scope.row.orderSkuPropertiesName }}</template>
                </el-table-column>
                <el-table-column label="档口号" width="125">
                  <template #default="scope">{{ scope.row.gearOpenNum }}</template>
                </el-table-column>
                <el-table-column label="拿货档口" width="125">
                  <template #default="scope">{{ scope.row.gearOpenName }}</template>
                </el-table-column>
                <el-table-column label="拿货数量" width="125">
                  <template #default="scope">{{ scope.row.orderNum }}</template>
                </el-table-column>
                <el-table-column label="拿货价" width="125">
                  <template #default="scope">{{ scope.row.purchasePrice }} <span style="color: skyblue;"
                      class="headclass" @click="openEvery(scope.row)">更多</span>
                  </template>
                </el-table-column>
                <el-table-column label="卖家备注" width="225">
                  <template #default="scope"><img style="width: 20px;height: 20px " :src="'http://yitaoweb.sc.kuaidi600.com/flag_color/op_memo_' +
                    Number(scope.row.sellerFlag) +
                    '.png'
                    " alt="" />{{ scope.row.sellerMemo }}</template>
                </el-table-column>
                <el-table-column label="订单状态" width="125">
                  <template #default="scope">{{ scope.row.orderStatus }}</template>
                </el-table-column>
                <el-table-column label="拿货状态" width="125">
                  <template #default="scope">{{ (scope.row.isGetGood == 1 ? '未拿货' : scope.row.isGetGood == 2 ?
                    '已拿货' : scope.row.isGetGood == 3 ? "缺货" : '') + ',' + (!!scope.row.getGoodDate ?
                      scope.row.getGoodDate.slice(0, 10) +
                      '到货' : '') }}</template>
                </el-table-column>
                <el-table-column label="是否虚拟发货" width="125">
                  <template #default="scope">{{ scope.row.isSend == 1 ? '是' : scope.row.isSend == 0 ? '否' : ''
                    }}</template>
                </el-table-column>
                <el-table-column label="操作" width="300">
                  <template #default="scope">
                    <el-button link type="primary" size="small" @click.prevent="stockoutBtn(scope.row)">
                      缺货
                    </el-button>
                    <el-button link type="primary" size="small" @click.prevent="printOneEvery(scope.row)">
                      <span v-if="scope.row.isPrint === 0">打印标签</span> <span v-if="scope.row.isPrint === 1">重新打印</span>
                    </el-button>
                    <el-button link type="primary" size="small" @click.prevent="preDeliveryPurchasing(scope.row)">
                      返回线上采购
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
        </el-tabs>

      </el-tab-pane>
    </el-tabs>
  </div>

  <div class="page">
    <el-pagination v-model:current-page="currentPage4" v-model:page-size="pageSize4" :page-sizes="[10, 50, 100]"
      layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
      @current-change="handleCurrentChange" />
  </div>
  <div>
    <el-dialog v-model="ApprovedbydialogVisible" width="500">
      <span>
        <strong>
          有订单处于缺货状态，请选择相应的处理方式
        </strong>
      </span>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="ApprovedbydialogVisible = false">取消</el-button>
          <el-button type="primary" @click="regainOrderEvery(ids)" v-if="loading">
            返回线上采购
          </el-button>
          <el-button type="primary" @click="preDeliveryBtn(ids)" v-if="typname == '供应链' && loading">
            提前发货
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
  <!-- 缺货 -->
  <div>
    <el-dialog v-model="stockoutTimesdialogVisible" width="500">
      <span>
        <el-date-picker v-model="stockoutTimes" type="datetime" />
      </span>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="stockoutTimesdialogVisible = false">取消</el-button>
          <el-button type="primary" @click="stockoutTimesSubmit(ids)">
            确定
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
  <!-- 拿货价 -->
  <div>
    <el-dialog v-model="purchasePricedialogVisible" width="750">
      <div v-if="purchasePriceOr">
        <el-form :model="purchasePriceform" inline>
          <el-form-item label="出库价">
            <el-input v-model="purchasePriceform.outPrice" />
          </el-form-item>
          <el-form-item label="拿货价">
            <el-input v-model="purchasePriceform.purchasePrice" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="setpurchasePriceOnSubmit">确定</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-table :data="purchasePricetableData" border style="width: 100%">
        <el-table-column prop="outPrice" label="出库价" width="120" />
        <el-table-column prop="purchasePrice" label="拿货价" width="120" />
        <el-table-column prop="createTime" label="记录时间" width="220" />
        <el-table-column label="操作" width="300">
          <template #default="scope">
            <el-button link type="primary" size="small" @click.prevent="setpurchasePriceOr(scope.row)">
              修改
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>

</template>

<script setup>
import { ref, onBeforeMount, onMounted, onBeforeUnmount } from 'vue'
// addPerPickOrder, , prePickOrderBatchPrintExpressOrder, getPrePickOrderDetail,prePickOrderlist ,
import {
  preSaleOrderList, expressNumberFaillist, pickSaleOrderlist, pickSaleOrderbackOnLinePre, expressNumberFailignoreOrder, productGearPurchaseCreate, preSaleOrderGetProductIdBySkuId, expressNumberFailGetFailMsgList, expressNumberFailprintExpressOrder, preSaleOrderbackOnLinePre, preSaleOrderbatchApprove, advanceSendOrderBackOnLinePre, preSaleOrderBatchBackOnLinePre, preSaleOrderbatchAdvanceSend, advanceSendOrderUpdatePurchasePrice, advanceSendOrderbathPrint, togetherHandleOrder, pickSaleOrdergetShopNameList, getWarehouseLocationIdList, pickSaleOrdergetOrderStatusList, pickSaleOrderGetPickPersonList, pickSaleOrderBatchPrint, pickSaleOrderBathVirtuallySend, getShopExpressCodeList, expressNumberFailchangeExpress, advanceSendOrderGetGearOpenList,
  advanceSendOrderGetSellerFlagList, advanceSendOrdershortage, advanceSendOrderBathVirtuallySend, advanceSendOrderskuPurchasePriceList,
  advanceSendOrdergetShopNameList,
  advanceSendOrderList
} from '@/api/index'
import { useAlertsStore } from '@/store/index'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'
const router = useRouter()
const store = useAlertsStore()
const activeName = ref('待审核')
const activeNameSon = ref('未虚拟发货')
const handleClick = (tab, event) => {
  console.log(tab, '113123123')
  if (tab) {
    console.log('tab')
    activeName.value = tab.props ? tab.props.name : activeName.value
  }
  if (activeName.value === '待审核') {
    console.log('1123')
    ToBeReviewedOnSubmit()
  }
  // if (tab.props.name === '拣货单列表') {
  //   console.log('1123')
  //   pickingListFormOnSubmit()
  // }
  if (activeName.value === '待拣货') {
    console.log('1123')
    pickingListFormOnSubmit()
  }
  if (activeName.value === '取号失败列表') {
    console.log('1123')
    failingListOnSubmit()
  }
  if (activeName.value === '提前发货') {
    console.log('1123')
    advanceSendOrderGetGearOpenList().then(res => {
      const { data: { data } } = res
      selectArr.value = data
      console.log(data)
    })
    preDeliveryListSelect()
  }
}
const selectArr = ref([])
onMounted(() => {
  doConnect()
  expressNumberFailGetFailMsgList().then(res => {
    const { data: { data } } = res
    console.log('data')
    console.log(data)
    loser.value = data
  })
})
const loser = ref([])
onBeforeMount(() => {
  store.preSaleOrdergetOrderTypeListBtn()
  store.getOrderPlatformListBtn()
  store.wareHouseSelect()
  store.getCompanyListBtn()
  getShopname()
  getWarehouseLocationIdListApi()
  pickSaleOrdergetOrderStatusListApi()
  FlagList()
  ShopNameList()
  getList()
})
// 店铺
const getShopnameArr = ref([])
const getShopname = () => {
  pickSaleOrdergetShopNameList().then(res => {
    const { data: { data } } = res
    console.log('店铺', data)
    getShopnameArr.value = data
  })
}
const WarehouseLocationIdList = ref([])
const getWarehouseLocationIdListApi = () => {
  getWarehouseLocationIdList().then(res => {
    const { data: { data } } = res
    console.log('库位', data)
    WarehouseLocationIdList.value = data
  })
}
const pickSaleOrdergetOrderStatusListArr = ref([])
const pickSaleOrdergetOrderStatusListApi = () => {
  pickSaleOrdergetOrderStatusList().then(res => {
    const { data: { data } } = res
    console.log('订单状态', data)
    pickSaleOrdergetOrderStatusListArr.value = data
  })
}
const pageForm = ref({
  pageSize: 10,
  pageNum: 1
})
// 旗帜
const flagArr = ref([])
const FlagList = () => {
  advanceSendOrderGetSellerFlagList().then(res => {
    const { data: { data } } = res
    flagArr.value = data
    console.log(data, 'qizi')
  })
}
const ShopNameListArr = ref([])
const ShopNameList = () => {
  advanceSendOrdergetShopNameList().then(res => {
    const { data: { data } } = res
    ShopNameListArr.value = data
    console.log(data, 'dianpu')
  })
}
// 待审核
const ToBeReviewed = ref({
  warehouseId: -1,
  tid: '',
  platformCode: '-1',
  company: '全部',
  typeId: -1

})
const ToBeReviewedOnSubmit = () => {
  console.log('submit!')
  getList()
}

// table多选
const multipleSelection = ref([])
const handleSelectionChange = (val) => {
  multipleSelection.value = val
}
const getList = () => {
  preSaleOrderList(Object.assign({}, ToBeReviewed.value, pageForm.value)).then(res => {
    const { data: { data } } = res
    console.log('data')
    console.log(data)
    total.value = data.total
    tableData.value = data.list
  })
}

// 拣货列表
const pickingListForm = ref({
  isSend: 0,
  warehouseId: -1,
  orderStatus: '全部',
  warehouseLocationId: -1,
  tid: '',
  shopName: '全部'
})
const pickingListTableData = ref([])
const pickingListFormOnSubmit = (tab) => {
  console.log('点击了')
  if (tab) {
    activeNameSon.value = tab.props ? tab.props.name : activeNameSon.value

    if (activeNameSon.value === '未虚拟发货') {
      pickingListForm.value.isSend = 0
    } else if (activeNameSon.value === '已虚拟发货') {
      pickingListForm.value.isSend = 1
    }
  }
  pickSaleOrderlist(Object.assign({}, pageForm.value, pickingListForm.value)).then(res => {
    const { data: { data } } = res
    total.value = data.total
    pickingListTableData.value = data.list
  })
}
// const pickingListFormOnSubmitSet = () => {
//   const a = []
//   if (multipleSelection.value) {
//     multipleSelection.value.forEach(e => {
//       a.push(e.id)
//     })
//     addPerPickOrder({
//       ids: a,
//       warehouseId: pickingListForm.value.warehouseId
//     }).then(res => {
//       ElMessage.success('操作成功')
//       pickingListFormOnSubmit()
//     })
//   } else {
//     ElMessage.error('选中数据')
//   }
// }
// const pickingListTableData = ref([])

// 待拣货
// const awaitPickForm = ref({
//   pageSize: 5,
//   pageNum: 1,
//   // warehouseId: '',
//   status: -1
// })
// const awaitPickTableData = ref([])
// const awaitPickonSubmit = () => {
//   console.log('待拣货')
//   prePickOrderlist({
//     warehouseId: awaitPickForm.value.warehouseId ? awaitPickForm.value.warehouseId : '',
//     orderNum: awaitPickForm.value.orderNum,
//     status: awaitPickForm.value.status,
//     pageSize: pageForm.value.pageSize,
//     pageNum: pageForm.value.pageNum
//   }).then(res => {
//     const { data: { data } } = res
//     total.value = data.total
//     awaitPickTableData.value = data.list
//   })
// }
// 取号失败列表
const failingListForm = ref({})
const failingListTable = ref([])
const failingListOnSubmit = () => {
  console.log('111')
  expressNumberFaillist({
    orderOid: failingListForm.value.orderOid,
    prePickOrderNum: failingListForm.value.prePickOrderNum,
    failMsg: failingListForm.value.failMsg,
    startTime: failingListForm.value.times ? failingListForm.value.times[0] : '',
    endTime: failingListForm.value.times ? failingListForm.value.times[1] : '',
    pageSize: pageForm.value.pageSize,
    pageNum: pageForm.value.pageNum
  }).then(res => {
    const { data: { data } } = res
    total.value = data.total
    failingListTable.value = data.list
  })
}
const failingListOnSubmitONe = () => {
  const a = []

  if (multipleSelection.value.length >= 0) {
    console.log('11111123123123')
    multipleSelection.value.forEach(e => {
      a.push(
        {
          id: e.id,
          sourceId: e.orderSource
        }
      )
    })
    togetherHandleOrder({
      bigIntIntegerDTOList: a
    }).then(res => {
      ElMessage.success('操作成功')
      failingListOnSubmit()
    })
  } else {
    ElMessage.error('选中数据')
  }
}
// 分页
const tableData = ref([])
const currentPage4 = ref(1)
const pageSize4 = ref(10)
const total = ref(0)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
  pageForm.value.pageSize = val
  handleClick()
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
  pageForm.value.pageNum = val
  handleClick()
}

// // 审核通过
// const verifiedBtn = (row) => {
//   preSaleOrderApprove({ id: row.id }).then(res => {
//     getList()
//     ElMessage.success('操作成功')
//   })
// }

const deleteRowPicking = (row) => {
  pickSaleOrderbackOnLinePre({ id: row.id }).then(res => {
    pickingListFormOnSubmit()
    ElMessage.success('操作成功')
  })
}
// 打印拣货单
// const getPrePickOrderDetailList = ref([])
// const getPrePickOrderDetailBtn = (row) => {
//   // router.push({ path: '/home/getPrePickOrderDetail', query: { id: 1, name: '打印' } })
//   getPrePickOrderDetail({ id: row }).then(res => {
//     const { data: { data } } = res
//     getPrePickOrderDetailList.value = data
//     if (localStorage.getItem('PrinterSetListJH')) {
//       const lists = JSON.parse(localStorage.getItem('PrinterSetListJH'))

//       const val = { cmd: 'print', requestID: '123458976', version: '1.0', task: { taskID: (new Date().getTime() + ''), preview: false, printer: lists[0].PrinterList, notifyMode: 'allInOne', previewType: 'pdf', documents: [{ documentID: '0123456789', contents: [{ data: { width: '210', height: '297', padding: '2', fontSize: '8', left: '2', skuInfo: getPrePickOrderDetailList.value, barcodeHeight: '43' }, templateURL: 'http://yitaoweb.sc.kuaidi600.com/moban/A4JH.xml' }] }] } }
//       store.socket.send(JSON.stringify(val))
//     } else {
//       ElMessage.error('先设置打印机')
//     }
//   })
// }
// const getPrePickOrderDetailPrePickOrderBtn = (row) => {
//   router.push({ path: '/home/getPrePickOrderDetail', query: { id: row, name: '详情' } })
// }
// const printProductPurchaseStorageBtn = (row) => {
//   const val = { cmd: 'print', requestID: '123458976', version: '1.0', task: { taskID: (new Date().getTime() + ''), preview: false, printer: '', notifyMode: 'allInOne', previewType: 'pdf', documents: [{ documentID: '0123456789', contents: [{ data: { width: '45', height: '35', padding: '2', barcodeHeight: '13', barcodeMargin: '1.8', fontSize: '8', showOrderName: '0', left: '2', waybillCode: '11231231231', skuInfo: '12311312' }, templateURL: 'http://yitaoweb.sc.kuaidi600.com/moban/express.xml' }] }] } }
//   store.socket.send(JSON.stringify(val))
// }

const doConnect = () => {
  console.log('d打开了不')
  store.socket = new WebSocket('ws://localhost:13528')
  // 打开Socket
  store.socket.onopen = function (event) {
    console.log('连接了')
    // 监听消息
    store.socket.onmessage = function (event) {
      console.log('接受了信息')
      // localStorage.setItem('printerproperties', event.data)
    }
    // 监听Socket的关闭
    store.socket.onclose = function (event) {
      // console.log('Client notified socket has closed', event)
    }
  }
}
// 销毁
onBeforeUnmount(() => {
  console.log('销毁')
  store.destroyed()
})
// // 打印
// const prePickOrderBatchPrintExpressOrderBtn = async (row) => {
//   store.destroyed()
//   doConnect()
//   await updateShopByOrderTitle([{
//     id: row.id,
//     sourceId: 1
//   }])
//   prePickOrderBatchPrintExpressOrder({
//     id: row
//   }).then(res => {
//     const { data: { data } } = res
//     console.log('1111')
//     let a = 1
//     if (localStorage.getItem('PrinterSetList')) {
//       data.forEach(element => {
//         a++
//         // const times = a
//         // console.log(times + '好的')
//         const lists = JSON.parse(localStorage.getItem('PrinterSetList'))
//         const val = { cmd: 'print', requestID: '123458976', version: '1.0', task: { taskID: (a + ''), preview: false, printer: lists[0].PrinterList, notifyMode: 'allInOne', previewType: 'pdf', documents: [{ documentID: '0123456789', contents: [JSON.parse(element)] }] } }
//         console.log(val)
//         store.socket.send(JSON.stringify(val))
//         // const lists = JSON.parse(localStorage.getItem('PrinterSetList'))
//         // const val = { cmd: 'print', requestID: '123458976', version: '1.0', task: { taskID: (+new Date() + times), preview: false, printer: lists[0].PrinterList, notifyMode: 'allInOne', previewType: 'pdf', documents: [{ documentID: '0123456789', contents: [JSON.parse(data[0])] }] } }
//         // console.log(JSON.stringify(val))
//         // store.socket.send(JSON.stringify(val))
//       })
//     } else {
//       ElMessage.error('先设置打印机')
//     }
//   })
// }

// // 批量打印
// const batchPrintExpress = () => {
//   if (multipleSelection.value.length > 0) {
//     multipleSelection.value.forEach(el => {
//       getPrePickOrderDetailBtn(el.id)
//     })
//   } else {
//     ElMessage.error('选中数据')
//   }
// }
// 档口
const shopeIdsProduct = ref('')
const stallDialogVisible = ref(false)
const openStallDiaog = (row) => {
  // shopeIdsProduct.value = row.id
  preSaleOrderGetProductIdBySkuId({ id: row.id }).then(res => {
    const { data: { data } } = res
    console.log('data')
    console.log(data)
    shopeIdsProduct.value = data
    store.productGearListBtn({
      productId: data,
      name: ''
    })
    stallDialogVisible.value = true
  })
}

const purchaseNum = ref('')
const productGearId = ref('')
const productGearPurchaseCreateSubmit = () => {
  productGearPurchaseCreate({
    productId: shopeIdsProduct.value,
    productGearId: productGearId.value,
    purchaseNum: purchaseNum.value
  }).then(res => {
    ElMessage.success('操作成功')
    router.push({ path: '/home/everyView/stallStockAwaitGet' })
  })
}
const ignoreOrderBtn = (row) => {
  loading.value = false
  expressNumberFailignoreOrder({ id: row.id }).then(res => {
    ElMessage.success('操作成功')
    failingListOnSubmit()
    loading.value = true
  })
}
const regainOrder = (row) => {
  expressNumberFailprintExpressOrder({ id: row.id, sourceId: row.orderSource }).then(res => {
    ElMessage.success('操作成功')
    failingListOnSubmit()
  }
  )
}
const regainOrderEvery = (row) => {
  loading.value = false
  preSaleOrderBatchBackOnLinePre({ ids: row.id }).then(res => {
    ElMessage.success('操作成功')
    ToBeReviewedOnSubmit()
    loading.value = true
    ApprovedbydialogVisible.value = false
  }
  )
}
const loading = ref(true)
// 提前发货
const preDeliveryBtn = (row) => {
  loading.value = false
  preSaleOrderbatchAdvanceSend({ ids: row.id }).then(res => {
    ElMessage.success('操作成功')
    ToBeReviewedOnSubmit()
    ApprovedbydialogVisible.value = false
    loading.value = true
  }
  )
}
const returnXs = (row) => {
  loading.value = false
  preSaleOrderbackOnLinePre({ id: row.id }).then(res => {
    ElMessage.success('操作成功')
    ToBeReviewedOnSubmit()
    loading.value = true
  })
}
const typname = ref('')
const ids = ref({ id: [] })
const ApprovedbydialogVisible = ref(false)
// 批量审核
const everyToBeReviewedOnSubmit = (row, val) => {
  if (row === 2) {
    console.log('没有')
    console.log(row)
    preSaleOrderbatchApprove({
      ids: [val.id]
    }).then(res => {
      const { data: { data } } = res
      if (data) {
        ids.value.id = JSON.parse(data).ids
        typname.value = JSON.parse(data).typeName
        ApprovedbydialogVisible.value = true
      } else {
        ToBeReviewedOnSubmit()
      }
    })
  } else if (row === 1) {
    console.log('youle')
    const id = []
    multipleSelection.value.forEach(e => {
      id.push(e.id)
    })
    preSaleOrderbatchApprove({
      ids: id
    }).then(res => {
      const { data: { data } } = res
      if (data) {
        ids.value.id = JSON.parse(data).ids
        typname.value = JSON.parse(data).typeName
        ApprovedbydialogVisible.value = true
      } else {
        ToBeReviewedOnSubmit()
      }
    })
  }
}
const toCheckSheet = () => {
  router.push({ path: '/home/everyView/checkSheet' })
}

// // 定义一个函数，它接收一个回调函数作为参数
// function doSomething (callback) {
//   // 执行一些操作...
//   console.log('执行完成！')

//   // 确保回调函数是一个函数
//   if (typeof callback === 'function') {
//     // 调用回调函数
//     callback()
//   }
// }

// // 定义一个回调函数
// function myCallback () {
//   console.log('回调函数被调用！')
// }

// // 调用doSomething函数，并将myCallback函数作为参数传递
// doSomething(myCallback)

// 提前发货列表
const preDeliveryForm = ref({
  warehouseId: '-1',
  tid: '',
  platformCode: '-1',
  sellerFlag: '-1',
  shopName: '全部',
  payStartTime: '',
  gearOpenId: -1,
  payEndTime: '',
  isSend: 0
})
const preDeliveryListTable = ref([])
const preDeliveryFormtimes = ref('')
const preDeliveryListSelect = (tab) => {
  if (tab) {
    advance.value = tab.props ? tab.props.name : advance.value

    if (advance.value === '未虚拟发货') {
      preDeliveryForm.value.isSend = 0
    } else if (advance.value === '已虚拟发货') {
      preDeliveryForm.value.isSend = 1
    }
  }
  // if (tab) {
  //   console.log('拣货提交', tab.props.name)
  //   if (tab.props.name === '未虚拟发货') {
  //     preDeliveryForm.value.isSend = 0
  //   } else if (tab.props.name === '已虚拟发货') {
  //     preDeliveryForm.value.isSend = 1
  //   }
  // }
  preDeliveryForm.value.payStartTime = preDeliveryFormtimes.value ? preDeliveryFormtimes.value[0] : ''
  preDeliveryForm.value.payEndTime = preDeliveryFormtimes.value ? preDeliveryFormtimes.value[1] : ''
  advanceSendOrderList(Object.assign({}, preDeliveryForm.value, pageForm.value)).then(res => {
    const { data: { data } } = res
    total.value = data.total
    preDeliveryListTable.value = data.list
    console.log(data, 'data')
  })
}

// 缺货
const stockoutTimesdialogVisible = ref(false)
const stockoutTimes = ref('')
const stockoutTimesForm = ref({
  id: 0,
  getGoodDate: ''
})
const stockoutBtn = (row) => {
  stockoutTimesForm.value.id = row.id
  stockoutTimesdialogVisible.value = true
}
const stockoutTimesSubmit = () => {
  console.log(new Date())
  const date = new Date(stockoutTimes.value)
  const year = date.getFullYear()
  const month = String(date.getMonth() + 1).padStart(2, '0')
  const day = String(date.getDate()).padStart(2, '0')
  const formattedDate = `${year}年${month}月${day}日`
  console.log(formattedDate)
  stockoutTimesForm.value.getGoodDate = formattedDate
  advanceSendOrdershortage(stockoutTimesForm.value).then(res => {
    ElMessage.success('操作成功')
    stockoutTimesdialogVisible.value = false
    preDeliveryListSelect()
  })
}
// 虚拟发货
const VirtualDelivery = (row) => {
  if (Object.prototype.toString.call(row) === '[object Object]') {
    advanceSendOrderBathVirtuallySend({
      ids: [row.id]
    }).then(res => {
      ElMessage.success('操作成功')
      preDeliveryListSelect()
    })
  } else if (Object.prototype.toString.call(row) === '[object Array]') {
    const a = []
    if (row.length > 0) {
      row.forEach(element => {
        a.push(element.id)
      })
      advanceSendOrderBathVirtuallySend({
        ids: a
      }).then(res => {
        ElMessage.success('操作成功')
        preDeliveryListSelect()
      })
    } else {
      ElMessage.error('请先选择数据')
    }
  }
}
const purchasePricedialogVisible = ref(false)
const purchasePriceOr = ref(false)
const purchasePriceform = ref({ id: '' })
const purchasePricetableData = ref([])
const everyId = ref('')
const openEvery = (row) => {
  if (row) {
    everyId.value = row.id
  }
  advanceSendOrderskuPurchasePriceList({ id: everyId.value }).then(res => {
    const { data: { data } } = res
    purchasePricetableData.value = data
    purchasePricedialogVisible.value = true
    console.log(data)
  })
}

const setpurchasePriceOr = (row) => {
  purchasePriceform.value.id = row.id
  purchasePriceOr.value = true
}
const setpurchasePriceOnSubmit = () => {
  advanceSendOrderUpdatePurchasePrice(purchasePriceform.value).then(res => {
    ElMessage.success('修改成功')
    purchasePriceform.value = { id: '' }
    openEvery()
    purchasePriceOr.value = false
  })
}
const printOneEvery = (row) => {
  if (Object.prototype.toString.call(row) === '[object Object]') {
    advanceSendOrderbathPrint({
      ids: [row.id]
    }).then(res => {
      const { data: { data } } = res
      console.log(data)
      if (localStorage.getItem('PrinterSetListKW')) {
        // data.forEach(e => {
        const lists = JSON.parse(localStorage.getItem('PrinterSetListKW'))
        const val = { cmd: 'print', requestID: '123458976', version: '1.0', task: { taskID: (+new Date() + ''), preview: false, printer: lists[0].PrinterList, notifyMode: 'allInOne', previewType: 'pdf', documents: [{ documentID: '0123456789', contents: [{ data: { width: '65', height: '38', padding: '2', barcodeHeight: '8', barcodeMargin: '1.8', fontSize: '8', showOrderName: '0', left: '2', datas: data[0] }, templateURL: 'http://yitaoweb.sc.kuaidi600.com/moban/expreesMy.xml' }] }] } }
        store.socket.send(JSON.stringify(val))
        // })
      } else {
        ElMessage.success('先设置打印机')
      }
    })
  } else if (Object.prototype.toString.call(row) === '[object Array]') {
    const a = []
    if (row.length > 0) {
      row.forEach(element => {
        a.push(element.id)
      })
      advanceSendOrderbathPrint({
        ids: a
      }).then(res => {
        const { data: { data } } = res
        console.log(data)
        let ab = 1
        if (localStorage.getItem('PrinterSetListKW')) {
          data.forEach(e => {
            ab++
            const lists = JSON.parse(localStorage.getItem('PrinterSetListKW'))
            const val = { cmd: 'print', requestID: '123458976', version: '1.0', task: { taskID: (new Date().getTime() + ab + ''), preview: false, printer: lists[0].PrinterList, notifyMode: 'allInOne', previewType: 'pdf', documents: [{ documentID: '0123456789', contents: [{ data: { width: '65', height: '38', padding: '2', barcodeHeight: '8', barcodeMargin: '1.8', fontSize: '8', showOrderName: '0', left: '2', datas: e }, templateURL: 'http://yitaoweb.sc.kuaidi600.com/moban/expreesMy.xml' }] }] } }
            store.socket.send(JSON.stringify(val))
          })
        } else {
          ElMessage.error('先设置打印机')
        }
      })
    } else {
      ElMessage.error('请先选择数据')
    }
  }
}
const preDeliveryPurchasing = (row) => {
  advanceSendOrderBackOnLinePre({ id: row.id }).then(res => {
    preDeliveryListSelect()
    ElMessage.success('操作成功')
  })
}
// 拣货单打印标签
const Tagform = ref({})
const PickPersonList = ref([])
const TagdialogVisible = ref(false)
const ContentBottom = ref('')
const printMyTag = async (row) => {
  const printList = await pickSaleOrderGetPickPersonList()
  console.log('printList')
  const { data: { data } } = printList
  console.log(data)
  data.forEach(e => {
    if (e.id === 1) {
      Tagform.value.getPeopleName = e.name
    }
  })
  PickPersonList.value = data
  ContentBottom.value = row
  TagdialogVisible.value = true
}
const submitTagPrint = (row) => {
  if (Object.prototype.toString.call(row) === '[object Object]') {
    pickSaleOrderBatchPrint({
      name: Tagform.value.getPeopleName,
      ids: [row.id]
    }).then(res => {
      const { data: { data } } = res
      console.log(data)
      if (localStorage.getItem('PrinterSetListKW')) {
        const lists = JSON.parse(localStorage.getItem('PrinterSetListKW'))
        const val = { cmd: 'print', requestID: '123458976', version: '1.0', task: { taskID: (new Date().getTime() + ''), preview: false, printer: lists[0].PrinterList, notifyMode: 'allInOne', previewType: 'pdf', documents: [{ documentID: '0123456789', contents: [{ data: { width: '65', height: '42', padding: '2', barcodeHeight: '8', barcodeMargin: '1.8', fontSize: '8', showOrderName: '0', left: '2', datas: data[0] }, templateURL: 'http://yitaoweb.sc.kuaidi600.com/moban/TagMy.xml' }] }] } }
        store.socket.send(JSON.stringify(val))
        pickingListFormOnSubmit()
        TagdialogVisible.value = false
      } else {
        ElMessage.success('先设置打印机')
      }
    })
  } else if (Object.prototype.toString.call(row) === '[object Array]') {
    const a = []
    if (row.length > 0) {
      row.forEach(element => {
        a.push(element.id)
      })
      pickSaleOrderBatchPrint({
        name: Tagform.value.getPeopleName,
        ids: a
      }).then(res => {
        const { data: { data } } = res
        console.log(data)
        let a = 1
        if (localStorage.getItem('PrinterSetListKW')) {
          data.forEach(element => {
            a++
            const lists = JSON.parse(localStorage.getItem('PrinterSetListKW'))
            const val = { cmd: 'print', requestID: '123458976', version: '1.0', task: { taskID: (new Date().getTime() + a + ''), preview: false, printer: lists[0].PrinterList, notifyMode: 'allInOne', previewType: 'pdf', documents: [{ documentID: '0123456789', contents: [{ data: { width: '65', height: '38', padding: '2', barcodeHeight: '8', barcodeMargin: '1.8', fontSize: '8', showOrderName: '0', left: '2', datas: element }, templateURL: 'http://yitaoweb.sc.kuaidi600.com/moban/TagMy.xml' }] }] } }
            store.socket.send(JSON.stringify(val))
            pickingListFormOnSubmit()
            TagdialogVisible.value = false
          })
        } else {
          ElMessage.error('先设置打印机')
        }
      })
    } else {
      ElMessage.error('请先选择数据')
    }
  }
}
// 虚拟发货
const TagVirtualDelivery = (row) => {
  const ids = []
  if (Object.prototype.toString.call(row) === '[object Object]') {
    pickSaleOrderBathVirtuallySend({
      ids: [row.id]
    }).then(res => {
      pickingListFormOnSubmit()
      ElMessage.success('操作成功')
    })
  } else if (Object.prototype.toString.call(row) === '[object Array]') {
    row.forEach(e => {
      ids.push(e.id)
    })
    pickSaleOrderBathVirtuallySend({ ids: ids }).then(res => {
      pickingListFormOnSubmit()
      ElMessage.success('操作成功')
    })
  }
}
const retlowSerDialogVisible = ref(false)
const rowNowContent = ref({})
const fatherProductPurchaseOrderCode = ref('')
const ExchangeExpress = (row) => {
  fatherProductPurchaseOrderCode.value = row
  retlowSerDialogVisible.value = true
  getShopExpressCodeList({
    id: row.id,
    sourceId: row.orderSource
  }).then(res => {
    const { data: { data } } = res
    rowNowContent.value = data
  })
}
const expressNow = ref('')
const submitExpress = () => {
  expressNumberFailchangeExpress({
    id: fatherProductPurchaseOrderCode.value.id,
    expressId: expressNow.value,
    sourceId: fatherProductPurchaseOrderCode.value.orderSource
  }).then(res => {
    ElMessage.success('操作成功')
    retlowSerDialogVisible.value = false
    failingListOnSubmit()
  })
}
const advance = ref('未虚拟发货')

</script>

<style lang='less' scoped>
.demo-tabs>.el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 600;
}

::v-deep .el-tabs__nav-wrap::after {
  background-color: #fff;
}
</style>
